package com.gzr.demo01.threadestate;

import com.gzr.demo01.TestRunnable3;

/**
 * 线程休眠-sleep
 * 模拟网络延迟
 */
public class TestSleep implements Runnable{
    private int ticketNums = 10;

    @Override
    public void run() {
        while (true) {
            if (ticketNums <= 0) {
                break;
            }

            //模拟延时
            try {
                Thread.sleep(200);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            System.out.println(Thread.currentThread().getName()+"拿到了第"+ticketNums--+"张票");
        }

    }

    public static void main(String[] args) {
        TestSleep runnable3 = new TestSleep();

        new Thread(runnable3,"张飞").start();
        new Thread(runnable3,"刘备").start();
        new Thread(runnable3,"关羽").start();
    }
}
